<template>
  <div>
    <ul>
      <li v-for="(item, index) in array" :key="index">
        {{ item }}
        <button @click="del(index)">删除</button>
      </li>
    </ul>
    <button @click="add">添加</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      array: [1, 2, 3],
    };
  },
  methods: {
    add() {
      this.array.push(Math.random().toFixed(2));
    },
    del(ind) {
      const id = this.array.findIndex((item) => item.index === ind);
      this.array.splice(id, 1);
    },
  },
};
</script>

<style></style>
